#include <REGX52.H>
#include "AT24C02.h"
#include "LCD1602.h"
#include "DelayTime.h"

void main()
{
	unsigned int num = 123;
	unsigned char Data;
	unsigned char key_num;
	LCD_Init();
	LCD_ShowNum(1,1,num,5);
	while(1)
	{
		key_num = Key_Num();
		if(key_num == 1) // ++
		{
			num++;
			LCD_ShowNum(1,1,num,5);
		}
		else if(key_num == 2) // --
		{
			num--;
			LCD_ShowNum(1,1,num,5);
		}
		else if(key_num == 3) // 存储
		{
			AT24C02_WriteByte(0,num / 256); // 高8位
			Delayxms(5);
			AT24C02_WriteByte(1,num % 256); // 低8位			
			Delayxms(5);
			LCD_ShowString(2,1,"Write OK");
			Delayxms(1000);
			LCD_ShowString(2,1,"        ");
		}
		else if(key_num == 4) // 加载
		{
			num |= (AT24C02_ReadByte(0) << 8);
			num |= AT24C02_ReadByte(1);
			LCD_ShowNum(1,1,num,5);
			LCD_ShowString(2,1,"Read OK");
			Delayxms(1000);		
			LCD_ShowString(2,1,"        ");			
		}
		
	}
}